<template>
  <div class="profile-container">
    <!-- 顶部个人信息概览 -->
    <div class="profile-header">
      <div class="header-content">
        <div class="user-basic">
          <el-avatar :size="100" src="https://via.placeholder.com/100" class="user-avatar" />
          <div class="user-main">
            <div class="user-title">
              <h1>{{ userInfo.username }}</h1>
              <el-tag type="warning" effect="dark">零食达人 Lv.{{ userInfo.level }}</el-tag>
            </div>
            <div class="user-badges">
              <el-tag size="small" effect="plain">已实名认证</el-tag>
              <el-tag size="small" effect="plain" type="success">信用良好</el-tag>
            </div>
            <div class="progress-bar">
              <span class="label">等级进度</span>
              <el-progress 
                :percentage="70" 
                :format="format" 
                status="warning"
                :stroke-width="10"
              />
            </div>
          </div>
        </div>
        <div class="user-stats-bar">
          <div class="stat-box">
            <span class="num">{{ userInfo.points }}</span>
            <span class="label">零食积分</span>
          </div>
          <div class="stat-box">
            <span class="num">{{ userInfo.orders }}</span>
            <span class="label">订单数</span>
          </div>
          <div class="stat-box">
            <span class="num">{{ userInfo.favorites }}</span>
            <span class="label">收藏数</span>
          </div>
          <div class="stat-box">
            <span class="num">12</span>
            <span class="label">优惠券</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="profile-main">
      <el-row :gutter="20">
        <!-- 左侧功能导航 -->
        <el-col :span="6">
          <div class="side-nav">
            <div class="nav-group">
              <h3 class="group-title">我的交易</h3>
              <el-menu 
                :default-active="activeMenu" 
                @select="handleMenuSelect"
                class="profile-menu"
              >
                <el-menu-item index="orders">
                  <el-icon><List /></el-icon>
                  <span>我的订单</span>
                </el-menu-item>
                <el-menu-item index="favorites">
                  <el-icon><Star /></el-icon>
                  <span>我的收藏</span>
                </el-menu-item>
                <el-menu-item index="coupons">
                  <el-icon><Ticket /></el-icon>
                  <span>优惠券</span>
                </el-menu-item>
              </el-menu>
            </div>

            <div class="nav-group">
              <h3 class="group-title">个人设置</h3>
              <el-menu class="profile-menu">
                <el-menu-item index="address">
                  <el-icon><Location /></el-icon>
                  <span>收货地址</span>
                </el-menu-item>
                <el-menu-item index="security">
                  <el-icon><Lock /></el-icon>
                  <span>账号安全</span>
                </el-menu-item>
              </el-menu>
            </div>

            <!-- 会员特权卡片 -->
            <div class="vip-card">
              <div class="vip-header">
                <img src="https://via.placeholder.com/40" alt="VIP" class="vip-icon">
                <span>尊享会员</span>
              </div>
              <div class="vip-benefits">
                <div class="benefit-item">
                  <el-icon><Discount /></el-icon>
                  <span>9.5折优惠</span>
                </div>
                <div class="benefit-item">
                  <el-icon><Present /></el-icon>
                  <span>生日礼包</span>
                </div>
                <div class="benefit-item">
                  <el-icon><Star /></el-icon>
                  <span>积分双倍</span>
                </div>
              </div>
              <el-button type="warning" class="upgrade-btn">升级会员</el-button>
            </div>
          </div>
        </el-col>

        <!-- 右侧内容区 -->
        <el-col :span="18">
          <div class="content-area">
            <!-- 快捷操作区 -->
            <div class="quick-actions" v-if="activeMenu === 'orders'">
              <div class="action-item" v-for="action in quickActions" :key="action.type">
                <el-badge :value="action.count" :hidden="!action.count">
                  <div class="action-icon">
                    <el-icon><component :is="action.icon" /></el-icon>
                  </div>
                </el-badge>
                <span>{{ action.label }}</span>
              </div>
            </div>

            <!-- 订单列表 -->
            <div v-if="activeMenu === 'orders'" class="orders-panel">
              <div class="panel-header">
                <h2>我的订单</h2>
                <el-radio-group v-model="orderType" size="small">
                  <el-radio-button label="all">全部</el-radio-button>
                  <el-radio-button label="unpaid">待付款</el-radio-button>
                  <el-radio-button label="undelivered">待发货</el-radio-button>
                  <el-radio-button label="delivered">待收货</el-radio-button>
                </el-radio-group>
              </div>

              <div class="order-cards">
                <el-card v-for="order in filteredOrders" :key="order.id" class="order-card">
                  <div class="order-header">
                    <span class="order-time">{{ order.time }}</span>
                    <el-tag :type="order.statusType" size="small">{{ order.status }}</el-tag>
                  </div>
                  <div class="order-products">
                    <img :src="order.image" class="product-image">
                    <div class="order-info">
                      <h4>{{ order.products }}</h4>
                      <div class="order-footer">
                        <span class="total-price">¥{{ order.total.toFixed(2) }}</span>
                        <div class="order-actions">
                          <el-button type="primary" size="small" plain>查看详情</el-button>
                          <el-button 
                            type="warning" 
                            size="small" 
                            v-if="order.status === '待付款'"
                          >
                            立即付款
                          </el-button>
                        </div>
                      </div>
                    </div>
                  </div>
                </el-card>
              </div>
            </div>

            <!-- 收藏商品 -->
            <div v-if="activeMenu === 'favorites'" class="favorites-panel">
              <div class="panel-header">
                <h2>我的收藏</h2>
                <el-input
                  v-model="searchFavorites"
                  placeholder="搜索收藏的商品"
                  prefix-icon="Search"
                  clearable
                  class="search-input"
                />
              </div>

              <el-row :gutter="20">
                <el-col 
                  :span="8" 
                  v-for="item in filteredFavorites" 
                  :key="item.id"
                >
                  <div class="favorite-card">
                    <div class="favorite-image">
                      <img :src="item.image" :alt="item.name">
                      <div class="image-overlay">
                        <el-button type="primary" circle>
                          <el-icon><ShoppingCart /></el-icon>
                        </el-button>
                        <el-button type="danger" circle>
                          <el-icon><Delete /></el-icon>
                        </el-button>
                      </div>
                    </div>
                    <div class="favorite-content">
                      <h3>{{ item.name }}</h3>
                      <div class="favorite-footer">
                        <span class="price">¥{{ item.price.toFixed(2) }}</span>
                        <el-tag size="small" type="info">{{ item.category }}</el-tag>
                      </div>
                    </div>
                  </div>
                </el-col>
              </el-row>
            </div>

            <!-- 优惠券面板 -->
            <div v-if="activeMenu === 'coupons'" class="coupons-panel">
              <div class="panel-header">
                <h2>我的优惠券</h2>
                <el-radio-group v-model="couponStatus" size="small">
                  <el-radio-button label="valid">未使用</el-radio-button>
                  <el-radio-button label="used">已使用</el-radio-button>
                  <el-radio-button label="expired">已过期</el-radio-button>
                </el-radio-group>
              </div>

              <div class="coupon-list">
                <div 
                  v-for="coupon in filteredCoupons" 
                  :key="coupon.id" 
                  class="coupon-item"
                  :class="{ 'expired': coupon.expired }"
                >
                  <div class="coupon-left">
                    <span class="amount">¥{{ coupon.amount }}</span>
                    <span class="condition">{{ coupon.condition }}</span>
                  </div>
                  <div class="coupon-right">
                    <h4>{{ coupon.title }}</h4>
                    <p class="validity">有效期至：{{ coupon.expireDate }}</p>
                    <el-button 
                      size="small" 
                      :type="coupon.expired ? 'info' : 'primary'"
                      :disabled="coupon.expired"
                    >
                      {{ coupon.expired ? '已过期' : '立即使用' }}
                    </el-button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { 
  List, Star, Ticket, Location, Delete, Lock,
  Plus, Discount, Present, Search, ShoppingCart
} from '@element-plus/icons-vue'

// ... 其他代码保持不变 ...

// 新增数据
const activeMenu = ref('orders')
const orderType = ref('all')
const couponStatus = ref('valid')
const searchFavorites = ref('')

const quickActions = [
  { type: 'unpaid', label: '待付款', icon: 'Wallet', count: 2 },
  { type: 'undelivered', label: '待发货', icon: 'Box', count: 1 },
  { type: 'delivered', label: '待收货', icon: 'Van', count: 3 },
  { type: 'review', label: '待评价', icon: 'ChatDotRound', count: 0 }
]

// 计算属性
const filteredOrders = computed(() => {
  if (orderType.value === 'all') return orders.value
  return orders.value.filter(order => order.type === orderType.value)
})

const filteredFavorites = computed(() => {
  if (!searchFavorites.value) return favorites.value
  return favorites.value.filter(item => 
    item.name.toLowerCase().includes(searchFavorites.value.toLowerCase())
  )
})

const filteredCoupons = computed(() => {
  return coupons.value.filter(coupon => {
    if (couponStatus.value === 'valid') return !coupon.expired && !coupon.used
    if (couponStatus.value === 'used') return coupon.used
    return coupon.expired
  })
})

// 方法
const handleMenuSelect = (index) => {
  activeMenu.value = index
}

const format = percentage => {
  return `${percentage}/100`
}
</script>

<style scoped>
.profile-container {
  min-height: 100vh;
  background: #f5f7fa;
}

.profile-header {
  background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
  padding: 40px 0;
  color: white;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.user-basic {
  display: flex;
  align-items: center;
  gap: 30px;
  margin-bottom: 30px;
}

.user-avatar {
  border: 4px solid rgba(255, 255, 255, 0.3);
}

.user-main {
  flex: 1;
}

.user-title {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 10px;
}

.user-title h1 {
  margin: 0;
  font-size: 24px;
}

.user-badges {
  margin: 10px 0;
  display: flex;
  gap: 10px;
}

.progress-bar {
  max-width: 300px;
}

.progress-bar .label {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.user-stats-bar {
  display: flex;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 20px;
}

.stat-box {
  text-align: center;
}

.stat-box .num {
  display: block;
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 5px;
}

.stat-box .label {
  font-size: 14px;
  opacity: 0.8;
}

.profile-main {
  max-width: 1200px;
  margin: -30px auto 0;
  padding: 0 20px;
  position: relative;
}

.side-nav {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.nav-group {
  margin-bottom: 30px;
}

.group-title {
  font-size: 16px;
  color: #666;
  margin: 0 0 15px;
  padding-left: 10px;
}

.profile-menu {
  border-right: none;
}

.vip-card {
  background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  border-radius: 12px;
  padding: 20px;
  color: white;
  margin-top: 30px;
}

.vip-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.vip-benefits {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  margin-bottom: 20px;
}

.benefit-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.upgrade-btn {
  width: 100%;
}

.content-area {
  background: white;
  border-radius: 12px;
  padding: 30px;
  min-height: 600px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 30px;
}

.action-item {
  text-align: center;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.action-item:hover {
  background: #f0f0f0;
}

.action-icon {
  font-size: 24px;
  margin-bottom: 10px;
  color: #ff6b6b;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.panel-header h2 {
  margin: 0;
  font-size: 20px;
  color: #333;
}

.order-card {
  margin-bottom: 20px;
}

.order-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}

.favorite-card {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s;
}

.favorite-card:hover {
  transform: translateY(-5px);
}

.favorite-image {
  position: relative;
  height: 200px;
}

.favorite-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  opacity: 0;
  transition: opacity 0.3s;
}

.favorite-card:hover .image-overlay {
  opacity: 1;
}

.favorite-content {
  padding: 15px;
}

.favorite-content h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.favorite-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.coupon-item {
  display: flex;
  background: white;
  border-radius: 8px;
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.coupon-left {
  background: #ff6b6b;
  color: white;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-width: 120px;
}

.coupon-right {
  flex: 1;
  padding: 20px;
}

.amount {
  font-size: 24px;
  font-weight: bold;
}

.condition {
  font-size: 12px;
  opacity: 0.8;
}

.validity {
  color: #999;
  font-size: 12px;
  margin: 5px 0;
}

.expired {
  filter: grayscale(1);
  opacity: 0.7;
}

@media (max-width: 768px) {
  .quick-actions {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .user-stats-bar {
    flex-wrap: wrap;
  }
  
  .stat-box {
    width: 50%;
    margin-bottom: 20px;
  }
}
</style> 